package com.cloudcms.web.handler;

import com.cloudcms.web.util.Constants;
import com.cloudcms.web.util.CommUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author lv
 *
 */
public class SessionIdInterceptor extends HandlerInterceptorAdapter {
	private final Logger logger = LoggerFactory.getLogger(SessionIdInterceptor.class);
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		logger.info("request请求地址path[{}] uri[{}]", request.getServletPath(),request.getRequestURI());
        HttpSession session = request.getSession();
        Cookie[] cookies = request.getCookies();

        String sessionid = "";
        if (session.getAttribute(Constants.COOKIEPREFIX)==null) {
            sessionid = CommUtil.generateToken(request);
            //session.setAttribute(Constants.COOKIEPREFIX,sessionid);
        }
        return true;
	}
}
